{{extend '../_layouts/home.html'}}

{{block 'title'}}{{'多人博客 - 首页'}}{{/block}}

{{block 'body'}}
<section class="container">
  {{include '../_partials/settings-nav.html'}}
  <div class="col-md-5">
    <div class="subhead">
      <h2>修改密码</h2>
    </div>
    <hr>
    <form id="adminBtn">
      <div class="form-group">
        <label for="exampleInputPassword1">当前密码</label>
        <input required type="password" class="form-control" id="password1" placeholder="">
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">新的密码</label>
        <input required type="password" class="form-control" id="password2" placeholder="">
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">确认密码</label>
        <input required type="password" class="form-control" id="password3" placeholder="">
      </div>
      <button type="submit" class="btn btn-success">保存</button>
    </form>
    
    <hr>
  </div>
</section>
{{/block}}
{{block "script"}}
<script>
$("#adminBtn").submit(function (e){
  e.preventDefault()
  var a = $("#password1").val()
  var b =$("#password2").val()
  if(a!==b){
    alert("两次旧密码不一致");
    return false
  }

  $.ajax({
    type:"post",
    url:"/admin",
    data:{
      olds:$("#password1").val(),
      news:$("#password3").val()
    },
    success:()=>{
      alert("修改成功")
      window.location.href="/"
    },
    error:()=>{
      alert("修改失败")
    }
  })
  
})
</script>
{{/block}}
